home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
TURB_VIS
/
RESDMP11
/
RESDUTIL.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-03-02
|
14KB
|
484 lines
{$A+,B-,D+,E+,F-,G-,I+,L-,N-,O-,P-,Q-,R-,S+,T-,V+,X+,Y-}
{$M 16384,0,655360}
{uses unit KEYNAMER.PAS (corrected!) from examples of TURBO PASCAL 7.0,
copyright 1992 by Borland,
uses ShoeHorn function from RESEDIT 2.0, copyright 1992 by Blaise Comp.}
unit resdutil;
interface
uses DOS,drivers,objects,views,dialogs;
FUNCTION FDate : String;
FUNCTION FTime : String;
FUNCTION FBase ( s : PathStr ) : String;
FUNCTION FileExist ( p : PathStr ) : boolean;
FUNCTION KeyName( key: word): String;
FUNCTION ReplaceControl(Dialog : PDialog;
Control : PView;
CurHelpCtx:word;
CurTypeOf : Pointer ) : PView;
implementation
FUNCTION FileExist ( p : PathStr ) : boolean;
VAR f : text;
BEGIN
Assign(f,p);
{$I-}Reset(f);{$I+}
IF IOResult<>0
THEN FileExist := false
ELSE BEGIN FileExist := true; close(f) END;
END;
FUNCTION FBase ( s : PathStr ) : String;
VAR d : DirStr; n : NameStr; e : ExtStr;
BEGIN
FSplit ( s, d, n, e );
FBase := n+e;
END;
FUNCTION FDate : String;
CONST DateFormat : String = '%02d.%02d.%02d';
VAR Params : ARRAY[1..3] OF longint;
i : integer;
d,m,y,wd : word;
td : String;
BEGIN
GetDate(y,m,d,wd); y := y-1900;
Params[1] := d;
Params[2] := m;
Params[3] := y;
Formatstr(td,DateFormat,Params);
FDate := copy(td, 1, 8 );
END; {FUNC FDate}
FUNCTION FTime : String;
CONST TimeFormat = '%02d:%02d:%02d';
VAR Params : RECORD lh,lm,ls,lcs : longint; END;
h,m,s,cs : word;
ts : String;
BEGIN
GetTime(h,m,s,cs);
WITH Params DO
BEGIN lh := h; lm := m; ls := s; lcs := cs; END;
Formatstr(ts,TimeFormat,Params);
FTime := ts;
END; {FUNC FTime}
function KeyName( key: word): String;
const
QWERTY: String[10] = 'QWERTYUIOP';
ASDF: String[9] = 'ASDFGHJKL';
ZXCV: String[7] = 'ZXCVBNM';
var
st: String;
begin
KeyName:='';
case key of
0..31: KeyName:= 'Control-'+char(key+64);
32: KeyName:= 'Spacebar';
33..125: KeyName:= Char(key);
$011B: KeyName:= 'kbEsc';
$0200: KeyName:= 'kbAltSpace';
$0400: KeyName:= 'kbCtrlIns';
$0500: KeyName:= 'kbShiftIns';
$0600: KeyName:= 'kbCtrlDel';
$0700: KeyName:= 'kbShiftDel';
$0E08: KeyName:= 'kbBack';
$0E7F: KeyName:= 'kbCtrlBack';
$0F00: KeyName:= 'kbShiftTab';
$0F09: KeyName:= 'kbTab';
$1C0A: KeyName:= 'kbCtrlEnter';
$1C0D: KeyName:= 'kbEnter';
$4700: KeyName:= 'kbHome';
$4800: KeyName:= 'kbUp';
$4900: KeyName:= 'kbPgUp';
$4A2D: KeyName:= 'kbGrayMinus';
$4B00: KeyName:= 'kbLeft';
$4D00: KeyName:= 'kbRight';
$4E2B: KeyName:= 'kbGrayPlus';
$4F00: KeyName:= 'kbEnd';
$5000: KeyName:= 'kbDown';
$5100: KeyName:= 'kbPgDn';
$5200: KeyName:= 'kbIns';
$5300: KeyName:= 'kbDel';
$7200: KeyName:= 'kbCtrlPrtSc';
$7300: KeyName:= 'kbCtrlLeft';
$7400: KeyName:= 'kbCtrlRight';
$7500: KeyName:= 'kbCtrlEnd';
$7600: KeyName:= 'kbCtrlPgDn';
$7700: KeyName:= 'kbCtrlHome';
$8200: KeyName:= 'kbAltMinus';
$8300: KeyName:= 'kbAltEqual';
$8400: KeyName:= 'kbCtrlPgUp';
$0000: KeyName:= 'kbNoKey';
else
if Lo(key) = 0 then
begin
key := hi(key);
case key of
$10..$19: KeyName:= 'kbAlt'+ QWERTY[key-$0F];
$1E..$26: KeyName:= 'kbAlt'+ ASDF[key-$1D];
$2C..$32: KeyName:= 'kbAlt'+ ZXCV[key-$2B];
$3B..$44:
begin
Str((key-$3A):0,st);
KeyName:= 'kbF'+st;
end;
$54..$5D:
begin
Str((key-$53):0,st);
KeyName:= 'kbShiftF'+st;
end;
$5E..$67:
begin
Str((key-$5D):0,st);
KeyName:= 'kbCtrlF'+st;
end;
$68..$71:
begin
Str((key-$67):0,st);
KeyName:= 'kbAltF'+st;
end;
$78..$80:
begin
Str((key-$77):0,st);
KeyName:= 'kbAlt'+st;
end;
$81: KeyName:= 'kbAlt0';
end; {case}
end;
end; {case}
end;
{---------------------------------------------------------------}
{ Description:
Replace a control in a dialog box with a user "custom" control
function ReplaceControl(Dialog : PDialog;
Control : PView;
CurHelpCtx:word;
CurTypeOf : Pointer ) : PView;
Dialog Pointer to the dialog box to insert user
control
Control Pointer to the user control to insert into
the abstract control position
CurHelpCtx Help context of abstract control to be replaced
CurTypeOf TypeOf abstract control to be replaced
in case two controls share the same HelpCtx
This function replaces a control view in a dialog box
with Control, which must be of a descendent type. It
essentially swaps one control for another, setting the
size and location of the new view with that of the
original, and then disposing of the original.
This function is an extended version of function
bShoeHorn in the Blaise ResEdit package.
Extension made by W. Gross. Blame him for any bugs.
}
CONST ofShoeHorn = $8000;
VAR ownCurHelpCtx : word;
ownCurTypeOf : Pointer;
function ReplaceControl(Dialog : PDialog;
Control : PView;
CurHelpCtx : word;
CurTypeOf : Pointer) : PView;
var
DummyControl : PView;
OldListViewer : PListViewer;
NewListViewer : PListViewer;
OldButton : PButton;
NewButton : PButton;
OldCluster : PCluster;
NewCluster : PCluster;
OldILine : PInputLine;
NewILine : PInputLine;
OldSText : PStaticText;
NewSText : PStaticText;
OldPText : PParamText;
NewPText : PParamText;
LabelP : PLabel;
I : Integer;
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{ }
{ TestLabelPtr }
{ }
{ function TestLabelPtr(View : PView) : boolean; far; }
{ }
{ Description This function returns True if View is a label and its }
{ owner is DummyControl. }
{ }
{_____________________________________________________________________}
function TestLabelPtr(View : PView) : boolean; far;
begin {TestLabelPtr}
if (TypeOf(View^) = TypeOf(TLabel)) and
(PLabel(View)^.Link = PView(DummyControl)) then
begin
TestLabelPtr := True;
Exit;
end;
TestLabelPtr := False;
end; {TestLabelPtr}
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{ }
{ function TestReplaceProp(View : PView) : boolean; far; }
{ }
{ Description This function returns True if }
{ - the shoehorn bit, ofShoeHorn, is set in View's Options. }
{ - the HelpCtx equals CurHelpCtx }
{ - the TypeOf(View) equals CurTypeOf }
{ }
{_____________________________________________________________________}
function TestReplaceProp(View : PView) : boolean; far;
begin {TestShoeHornBit}
TestReplaceProp := ((View^.Options and ofShoeHorn) <> 0) AND
(View^.HelpCtx=ownCurHelpCtx) AND
(TypeOf(View^)=ownCurTypeOf);
end; {TestReplaceProp}
begin {ReplaceControl}
{ Look in Z-order for first control with
- shoehorn bit set,
- HelpCtx=CurHelpCtx
- TypeOf=CurTypeOf }
{need these own vars for TestReplaceProp}
ownCurHelpCtx := CurHelpCtx;
ownCurTypeOf := CurTypeOf;
DummyControl := PView(Dialog^.FirstThat(@TestReplaceProp));
if (DummyControl = NIL) then { Error ! }
begin
ReplaceControl := NIL;
Exit;
end
else
begin
{ See if a label points to the dummy control so we can change }
{ its link field. }
LabelP := PLabel(Dialog^.FirstThat(@TestLabelPtr));
if (LabelP <> NIL) then
LabelP^.Link := Control;
with Control^ do
begin
{ TView specific fields }
Owner := DummyControl^.Owner;
Next := DummyControl^.Next;
Origin := DummyControl^.Origin;
Size := DummyControl^.Size;
HelpCtx := DummyControl^.HelpCtx;
end;
{ Make sure the circular list is intact }
DummyControl^.Prev^.Next := Control;
{ We need to clear the owner field so that we avoid being }
{ deleted from the dialog box during Done (see TGroup.Done) }
DummyControl^.Owner := NIL;
{ Check the type of the original control to see which control }
{ specific fields we have to transfer to the new control. }
if (TypeOf(DummyControl^) = TypeOf(TListViewer)) then
begin
OldListViewer := PListViewer(DummyControl);
NewListViewer := PListViewer(Control);
with NewListViewer^ do
begin
{ TListViewer specific fields }
HScrollBar := OldListViewer^.HScrollBar;
if (HScrollBar <> NIL) then
HScrollBar^.SetParams(0,0,Range-1,1,1);
VScrollBar := OldListViewer^.VScrollBar;
if (VScrollBar <> NIL) then
VScrollBar^.SetParams(0,0,Range-1,Size.Y-1,1);
NumCols := OldListViewer^.NumCols;
TopItem := 0;
if (Dialog^.Current = PView(OldListViewer)) then
NewListViewer^.Select;
Dispose(OldListViewer,Done);
end;
end
else if (TypeOf(DummyControl^) = TypeOf(TButton)) then
begin
OldButton := PButton(DummyControl);
NewButton := PButton(Control);
with NewButton^ do
begin
{ TButton specific fields }
Title := NewStr(OldButton^.Title^);
Command := OldButton^.Command;
Flags := OldButton^.Flags;
AmDefault := OldButton^.AmDefault;
if (Dialog^.Current = PView(OldButton)) then
NewButton^.Select;
Dispose(OldButton,Done);
end;
end
else if ((TypeOf(DummyControl^) = TypeOf(TRadioButtons)) or
(TypeOf(DummyControl^) = TypeOf(TCheckBoxes))) then
begin
OldCluster := PCluster(DummyControl);
NewCluster := PCluster(Control);
with NewCluster^ do
begin
{ TCluster specific fields }
Value := OldCluster^.Value;
Sel := OldCluster^.Sel;
EnableMask := OldCluster^.EnableMask; {!!! TV 2.0 !!!}
{ If Strings is empty, then add the strings from the }
{ base control; otherwise, allow the user to also }
{ specify the strings at run time. }
if (Strings.Count = 0) then
begin
Strings.FreeAll;
Strings.SetLimit(OldCluster^.Strings.Count);
for I := 0 to (OldCluster^.Strings.Count - 1) do
Strings.AtInsert(I,
NewStr(PString(OldCluster^.Strings.At(I))^) );
end;
if (Dialog^.Current = PView(OldCluster)) then
NewCluster^.Select;
Dispose(OldCluster,Done);
end;
end
else if (TypeOf(DummyControl^) = TypeOf(TInputLine)) then
begin
OldILine := PInputLine(DummyControl);
NewILine := PInputLine(Control);
with NewILine^ do
begin
{ TInputLine specific fields }
if (Data <> nil) then
FreeMem( Data, MaxLen + 1 );
GetMem(Data, OldILine^.MaxLen + 1);
Data^ := OldILine^.Data^;
MaxLen := OldILine^.MaxLen;
CurPos := OldILine^.CurPos;
FirstPos := OldILine^.FirstPos;
SelStart := OldILine^.SelStart;
SelEnd := OldILine^.SelEnd;
Validator := OldILine^.Validator; {!!! TV 2.0 !!!}
end;
if (Dialog^.Current = PView(OldILine)) then
NewILine^.Select;
Dispose(OldILine,Done);
end
else if (TypeOf(DummyControl^) = TypeOf(TStaticText)) then
begin
OldSText := PStaticText(DummyControl);
NewSText := PStaticText(Control);
with NewSText^ do
begin
{ TStaticText specific fields }
Text := NewStr(OldSText^.Text^);
end;
if (Dialog^.Current = PView(OldSText)) then
NewSText^.Select;
Dispose(OldSText,Done);
end
else if (TypeOf(DummyControl^) = TypeOf(TParamText)) then
begin
OldPText := PParamText(DummyControl);
NewPText := PParamText(Control);
with NewPText^ do
begin
{ TParamText specific fields }
Text := NewStr(OldPText^.Text^);
ParamCount := OldPText^.ParamCount;
end;
if (Dialog^.Current = PView(OldPText)) then
NewPText^.Select;
Dispose(OldPText,Done);
end;
ReplaceControl := Control;
end;
end; {FUNC ReplaceControl}
end. {UNIT RESDUTIL}